#include <stdint.h>
#include <sys/types.h>
#include <sys/time.h>
#include <unistd.h> 
#include <stdlib.h>
#include <assert.h>
#include "app_platform/cntl_info.h"
#include "gisao.h"

using namespace erp::gis::ao;

CPP_SELF_DEFINE_START
/**
*  请在这里增加自定义的成员变量和函数及其他内容，否则无法合并代码
**/
#include "gisao_enum.h"
#include "erp/comm/erp_macro_define.h"

using namespace c2cent::library::wtimeelf;
using namespace c2cent::library::wwlog;

//接口ITIL上报配置
CItilGroup CGisAo::m_oGetIpAddressByIp_Group(GETIPADDRESSBYIP_REQ ,GETIPADDRESSBYIP_ERR,GETIPADDRESSBYIP_RSP,GETIPADDRESSBYIP_DEF);

CPP_SELF_DEFINE_END

/**
 *构建函数
 */
CGisAo::CGisAo(enum DeployMethod method)
{

}

/**
 *析构函数
 */
CGisAo::~CGisAo()
{

}


/**
 *每一次服务请求时，container都会调用此方法来清空数据
 */
void  CGisAo::Reset()
{

}


int  CGisAo::Initialize(IUserDefineCntl* pCntl)
{
    int32_t iRetCode=0;

    uint32_t dwLogSwitch=WLOG_OPEN|WLOG_KEY_OPEN|WLOG_ERR_OPEN;
    uint32_t dwCanLogRemote = 0;
    std::string strLogModule="ao_joms";

    std::cout<<"File:"<<__FILE__<<" Complie Date: "<<__DATE__<<" "<<__TIME__<<std::endl;

    GetUintConfig(LogSwitch);
    GetStringConfig(LogModule);
    GetUintConfig(CanLogRemote);

    // 初始化日志
    if( C2C_WWLOG->QuickInitForAPP2(strLogModule.c_str(),B2B2CWW_LOG_APP_FILE_PATH, dwCanLogRemote, dwLogSwitch)!= 0)
    {
            std::cerr << "C2C_WWLOG->QuickInitForAPP2 Failed" << std::endl;
            return -1;
    }
    C2C_WW_LOG("C2C_WWLOG->QuickInitForAPP2 OK!");

    return iRetCode;
}


/**
 *
 *  鏍规嵁IP鑾峰彇鍦板潃淇℃伅
 *
 *@param String machineKey: 鏈哄櫒鐮侊紝蹇呭～   [in]
 *@param String source: 璋冪敤鏉ユ簮锛屽繀濉�  [in]
 *@param uint32_t sceneId: 鍦烘櫙id锛屽繀濉�  [in]
 *@param Set ipList: IP鍒楄〃锛屽繀濉�  [in]
 *@param String inReserve: 璇锋眰淇濈暀瀛�  [in]
 *@param String errmsg: 閿欒淇℃伅  	[out]
 *@param Map ipAddress: 鍦板潃淇℃伅  	[out]
 *@param String outReserve: 杩斿洖淇濈暀瀛�  	[out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CGisAo::GetIpAddressByIp(
				const CCntlInfo& rCntlInfo,
				const std::string& strMachineKey,
				const std::string& strSource,
				uint32_t dwSceneId,
				const std::set<uint32_t >& setIpList,
				const std::string& strInReserve,
				std::string& strErrmsg,
				std::map<uint32_t,erp::gis::po::CIpAddressPo >& mapIpAddress,
				std::string& strOutReserve
	)
{
    int32_t iRetCode=0;

    m_strMachineKey=strMachineKey;
    m_strSource=strSource;
    m_dwSceneId=dwSceneId;
    m_dwOperatorUin=rCntlInfo.getOperatorUin();
    IPToString(rCntlInfo.getOperatorClientIP(),m_strClientIP);

    C2C_WW_LOG("GetAReq %s OpUin:%u MachineKey:%s Source:%s SceneId:%u Uin:%u ClientIP:%s",
                    __FUNCTION__,m_dwOperatorUin,m_strMachineKey.c_str(),m_strSource.c_str(),m_dwSceneId,m_strClientIP.c_str());

    //打印性能日志的同时进行接口的itil上报
    C2C_TIME_ELF_ITIL oWTimeElf(C2C_WWLOG,__FUNCTION__,&iRetCode,&m_oGetIpAddressByIp_Group);

    //TODO 具体的业务代码

    return iRetCode;
}

/**
 *
 *  鏍规嵁IP鑾峰彇鍦板尯鍒楄〃淇℃伅锛岀敱楂樺埌浣�
 *
 *@param String machineKey: 鏈哄櫒鐮侊紝蹇呭～   [in]
 *@param String source: 璋冪敤鏉ユ簮锛屽繀濉�  [in]
 *@param uint32_t sceneId: 鍦烘櫙id锛屽繀濉�  [in]
 *@param Set ipList: IP鍒楄〃锛屽繀濉�  [in]
 *@param String inReserve: 璇锋眰淇濈暀瀛�  [in]
 *@param String errmsg: 閿欒淇℃伅  	[out]
 *@param Map smallestRegion: 鍦板潃淇℃伅  	[out]
 *@param String outReserve: 杩斿洖淇濈暀瀛�  	[out]
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CGisAo::GetSmallestRegionByIp(
				const CCntlInfo& rCntlInfo,
				const std::string& strMachineKey,
				const std::string& strSource,
				uint32_t dwSceneId,
				const std::set<uint32_t >& setIpList,
				const std::string& strInReserve,
				std::string& strErrmsg,
				std::map<uint32_t,std::vector<erp::gis::po::CRegionPo > >& mapSmallestRegion,
				std::string& strOutReserve
	)
{
	uint32_t dwRet = 0;
	//TODO:业务代码
	
	return dwRet;
}
